/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package cc.ls51.vo;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 */
public class ResultObject extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	
	public ResultObject() {
		put("code", 1);
		put("msg", "操作成功");
	}
	public ResultObject(int code, String msg) {
		put("code", code);
		put("msg", msg);
	}
	public static ResultObject emptyData() {
		return new ResultObject(2,"查询数据为空");
	}

	public static ResultObject error() {
		return error(0, "未知异常，请联系管理员");
	}
	
	public static ResultObject error(String msg) {
		return error(0, msg);
	}
	
	public static ResultObject error(int return_code, String msg) {
		ResultObject r = new ResultObject();
		r.put("code", return_code);
		r.put("msg", msg);
		return r;
	}

	public static ResultObject ok(String msg) {
		ResultObject r = new ResultObject();
		r.put("msg", msg);
		return r;
	}
	public static ResultObject ok(int code, String msg) {
		ResultObject r = new ResultObject(code,msg);
		return r;
	}
	
	public static ResultObject ok(Map<String, Object> map) {
		ResultObject r = new ResultObject();
		r.putAll(map);
		return r;
	}
	
	public static ResultObject ok() {
		return new ResultObject();
	}

	@Override
	public ResultObject put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
